<template>
  <div style="margin:4px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="70px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model.trim="queryParams.userId"
          placeholder="请输入用户ID"
          clearable/>
      </el-form-item>
      <el-form-item label="用户账号" prop="userName">
        <el-input
          v-model.trim="queryParams.userName"
          placeholder="请输入用户账号"
          clearable/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="priceList" :default-expand-all="true">
      <el-table-column label="用户ID" align="center" prop="userId"/>
      <el-table-column label="用户账号" align="center" prop="userName"/>
      <el-table-column label="用户昵称" align="center" prop="nickName"/>
      <el-table-column label="用户角色" align="center" prop="remark"/>
      <el-table-column label="产品售价" align="center" type="expand" width="200">
        <template slot-scope="props">
          <el-row type="flex" justify="end" v-for="(item,index) of props.row.productVo">
            <el-col :span="3">
              <div class="d" style="height: 24.4px">
                {{ item.name }}
              </div>
            </el-col>
            <el-col :span="3">
              <div class="d" style="height: 24.4px">
                自用价格：{{ zeroTwo(item.basePricing) }}
              </div>
            </el-col>
            <el-col :span="7">
              <div class="d">
                推广售价：{{ zeroTwo(item.basePricing + Number(item.promotionAdd)) }} = {{ zeroTwo(item.basePricing) }}
                <div>
                  +<input v-model="item.promotionAdd" style="width: 50px;margin: 0 2px">
                  <button @click="setPrice({
                               userId: props.row.userId,
                               type: 'TGSY',
                               productId: item.id,
                               amount: item.promotionAdd})">修改
                  </button>
                </div>
              </div>
            </el-col>
            <el-col :span="7">
              <div class="d" v-if="props.row.roleId == 2 || props.row.roleId == 3">
                下级价格：{{ zeroTwo(item.basePricing + Number(item.basePriceAdd)) }} = {{ zeroTwo(item.basePricing) }}
                <div>
                  +<input v-model="item.basePriceAdd" style="width: 50px;margin: 0 2px">
                  <button @click="setPrice({
                               userId: props.row.userId,
                               type: 'XJTC',
                               productId: item.id,
                               amount: item.basePriceAdd})">修改
                  </button>
                </div>
              </div>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :pageSizes="[2, 6]"
      @pagination="getList"/>
  </div>
</template>

<script>
  import {productPriceList, setPrice} from "@/api/system/product";

  export default {
    name: "CustomizedPrice",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 定制价格表格数据
        priceList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 2,

          userId: null,
          userName: null
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      setPrice(item) {
        setPrice(item).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess('售价修改成功')
          } else {
            this.$modal.msgWarning(response.msg)
          }
          this.getList()
        })
      },
      /** 查询定制价格列表 */
      getList() {
        this.loading = true;
        productPriceList(this.queryParams).then(response => {
          this.priceList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
</script>
<style scoped>
  .d {
    display: flex;
    /*flex-direction: column;*/
    justify-content: center;
    align-items: center;
  }

  #d div {
    margin-bottom: 3px;
  }

</style>
